Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ResponseOps][Rules] Remove unintended internal Find routes API with public access #193757

Merged
merged 24 commits into from
Oct 23, 2024

Conversation

Zacqary
Copy link
Contributor

@Zacqary Zacqary commented Sep 23, 2024

Summary

Fixes #192957

Removes the internal/_find route from public access by moving the hard-coded options into the route builder functions.

@Zacqary Zacqary added release_note:fix Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v9.0.0 Feature:Alerting/RulesFramework Issues related to the Alerting Rules Framework v8.16.0 labels Sep 23, 2024
@Zacqary Zacqary requested a review from a team as a code owner September 23, 2024 16:47
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@obltmachine
Copy link

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

@Zacqary Zacqary added the backport:version Backport to applied version labels label Sep 23, 2024
@Zacqary
Copy link
Contributor Author

Zacqary commented Sep 23, 2024

@elasticmachine merge upstream

Copy link
Member

@cnasikas cnasikas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a unit test (x-pack/plugins/alerting/server/routes/rule/apis/find/find_rules_route.test.ts) to be sure we register the correct routes with the correct access?

@cnasikas cnasikas added backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) and removed backport:version Backport to applied version labels labels Sep 24, 2024
@Zacqary Zacqary requested a review from a team as a code owner September 25, 2024 17:24
@botelastic botelastic bot added the ci:project-deploy-observability Create an Observability project label Sep 25, 2024
Copy link
Contributor

@dominiqueclarke dominiqueclarke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obs-ux-management changes LGTM

Copy link
Contributor

@adcoelho adcoelho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approved the PR but I never liked how we structured the code in find_rules_route.ts and I think in part that is the reason we had the bug.

It is not the scope of this issue so I'll leave it up to you but I was thinking the following:

What is the point of having a buildFindRulesRoute function?

  1. It is not exported anywhere else.
  2. Its logic is completely different if the route is internal or external.
  3. the if else being based on the URL doesn't feel right, what if I wanted to "build a find rules route" that is internal but with a different URL?
  4. Why have the options as params? For the external API they are hardcoded, we can put them inside the if. For the internal route we don't need the options.

I think this aux buildFindRulesRoute function does more harm than good. We could move the code inside findRulesRoute and findInternalRulesRoute and have them be completely separate. (Maybe even separate files.)

@cnasikas
Copy link
Member

+1 to what @adcoelho said. Same for the integration tests.

@Zacqary
Copy link
Contributor Author

Zacqary commented Oct 16, 2024

@elasticmachine merge upstream

Copy link
Member

@cnasikas cnasikas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for splitting the routes into different files! What do you think of splitting also the integration files into find.ts and find_internal.ts?

@@ -332,7 +332,6 @@ export default function createFindTests({ getService }: FtrProviderContext) {
afterEach(() => objectRemover.removeAll());

findTestUtils('public', supertest, objectRemover);
findTestUtils('internal', supertest, objectRemover);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep this?

@Zacqary Zacqary enabled auto-merge (squash) October 21, 2024 18:48
@elasticmachine
Copy link
Contributor

elasticmachine commented Oct 21, 2024

💛 Build succeeded, but was flaky

  • Buildkite Build
  • Commit: 92d2a02
  • Kibana Serverless Image: docker.elastic.co/kibana-ci/kibana-serverless:pr-193757-92d2a02d72e4

Failed CI Steps

Test Failures

  • [job] [logs] Jest Tests #4 / AllCasesListGeneric Actions Row actions should delete a case

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
securitySolution 20.7MB 20.7MB +85.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
@kbn/test-suites-xpack 730 732 +2

Total ESLint disabled count

id before after diff
@kbn/test-suites-xpack 755 757 +2

History

Copy link
Member

@cnasikas cnasikas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your patience with the review in this PR!

@@ -22,6 +22,7 @@ export default function alertingTests({ loadTestFile, getService }: FtrProviderC

loadTestFile(require.resolve('./backfill'));
loadTestFile(require.resolve('./find'));
loadTestFile(require.resolve('./find_internal'));
loadTestFile(require.resolve('./find_with_post'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we do not need the find_with_post file anymore.

Copy link
Contributor

@banderror banderror left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rule Management changes LGTM. I pulled the PR and tested rule snoozing locally to confirm that our dependency on the internal find endpoint hasn't been impacted - everything seems to work fine.

Screenshot 2024-10-22 at 19 22 33

Thanks @Zacqary 👍 ✅

@Zacqary Zacqary merged commit 196caba into elastic:main Oct 23, 2024
47 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.16, 8.x

https://github.com/elastic/kibana/actions/runs/11473099213

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Oct 23, 2024
…public access (elastic#193757)

## Summary

Fixes elastic#192957

Removes the `internal/_find` route from public access by moving the
hard-coded `options` into the route builder functions.

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
(cherry picked from commit 196caba)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Oct 23, 2024
…public access (elastic#193757)

## Summary

Fixes elastic#192957

Removes the `internal/_find` route from public access by moving the
hard-coded `options` into the route builder functions.

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
(cherry picked from commit 196caba)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.16
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Oct 23, 2024
…I with public access (#193757) (#197358)

# Backport

This will backport the following commits from `main` to `8.16`:
- [[ResponseOps][Rules] Remove unintended internal Find routes API with
public access (#193757)](#193757)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Zacqary Adam
Xeper","email":"Zacqary@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-10-23T04:33:31Z","message":"[ResponseOps][Rules]
Remove unintended internal Find routes API with public access
(#193757)\n\n## Summary\r\n\r\nFixes #192957 \r\n\r\nRemoves the
`internal/_find` route from public access by moving the\r\nhard-coded
`options` into the route builder
functions.\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"196cabad9bbd0511219fc7833a62cb8a0bb61514","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:ResponseOps","v9.0.0","Feature:Alerting/RulesFramework","backport:prev-minor","ci:project-deploy-observability","v8.16.0"],"title":"[ResponseOps][Rules]
Remove unintended internal Find routes API with public
access","number":193757,"url":"https://github.com/elastic/kibana/pull/193757","mergeCommit":{"message":"[ResponseOps][Rules]
Remove unintended internal Find routes API with public access
(#193757)\n\n## Summary\r\n\r\nFixes #192957 \r\n\r\nRemoves the
`internal/_find` route from public access by moving the\r\nhard-coded
`options` into the route builder
functions.\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"196cabad9bbd0511219fc7833a62cb8a0bb61514"}},"sourceBranch":"main","suggestedTargetBranches":["8.16"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/193757","number":193757,"mergeCommit":{"message":"[ResponseOps][Rules]
Remove unintended internal Find routes API with public access
(#193757)\n\n## Summary\r\n\r\nFixes #192957 \r\n\r\nRemoves the
`internal/_find` route from public access by moving the\r\nhard-coded
`options` into the route builder
functions.\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"196cabad9bbd0511219fc7833a62cb8a0bb61514"}},{"branch":"8.16","label":"v8.16.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Zacqary Adam Xeper <Zacqary@users.noreply.github.com>
kibanamachine added a commit that referenced this pull request Oct 23, 2024
… with public access (#193757) (#197359)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[ResponseOps][Rules] Remove unintended internal Find routes API with
public access (#193757)](#193757)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Zacqary Adam
Xeper","email":"Zacqary@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-10-23T04:33:31Z","message":"[ResponseOps][Rules]
Remove unintended internal Find routes API with public access
(#193757)\n\n## Summary\r\n\r\nFixes #192957 \r\n\r\nRemoves the
`internal/_find` route from public access by moving the\r\nhard-coded
`options` into the route builder
functions.\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"196cabad9bbd0511219fc7833a62cb8a0bb61514","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:ResponseOps","v9.0.0","Feature:Alerting/RulesFramework","backport:prev-minor","ci:project-deploy-observability","v8.16.0"],"title":"[ResponseOps][Rules]
Remove unintended internal Find routes API with public
access","number":193757,"url":"https://github.com/elastic/kibana/pull/193757","mergeCommit":{"message":"[ResponseOps][Rules]
Remove unintended internal Find routes API with public access
(#193757)\n\n## Summary\r\n\r\nFixes #192957 \r\n\r\nRemoves the
`internal/_find` route from public access by moving the\r\nhard-coded
`options` into the route builder
functions.\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"196cabad9bbd0511219fc7833a62cb8a0bb61514"}},"sourceBranch":"main","suggestedTargetBranches":["8.16"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/193757","number":193757,"mergeCommit":{"message":"[ResponseOps][Rules]
Remove unintended internal Find routes API with public access
(#193757)\n\n## Summary\r\n\r\nFixes #192957 \r\n\r\nRemoves the
`internal/_find` route from public access by moving the\r\nhard-coded
`options` into the route builder
functions.\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"196cabad9bbd0511219fc7833a62cb8a0bb61514"}},{"branch":"8.16","label":"v8.16.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Zacqary Adam Xeper <Zacqary@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) ci:project-deploy-observability Create an Observability project Feature:Alerting/RulesFramework Issues related to the Alerting Rules Framework release_note:fix Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.16.0 v8.17.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ResponseOps][Rules] Remove unintended internal Find routes API with public access
10 participants